package client.domain.ui.centerPanel;

import client.KaitzenGWTSandbox;
import static client.domain.SandboxMainKeys.*;
import client.internationalization.SandboxConstants;
import client.internationalization.SandboxMessages;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.MouseMoveEvent;
import com.google.gwt.event.dom.client.MouseMoveHandler;
import com.google.gwt.event.dom.client.MouseOutEvent;
import com.google.gwt.event.dom.client.MouseOutHandler;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.PopupPanel;
import com.gwtext.client.core.EventObject;
import com.gwtext.client.widgets.Button;
import com.gwtext.client.widgets.Panel;
import com.gwtext.client.widgets.Window;
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
import com.gwtext.client.widgets.layout.VerticalLayout;

/**
 * User: nbarrios
 * Date: Nov 9, 2009
 */
public class SelectTabsToAddPopUp extends Window{

	//	Internationalization Strings
	private SandboxConstants constants = GWT.create(SandboxConstants.class);
	private SandboxMessages messages = GWT.create(SandboxMessages.class);

	//	Main Widgets
	private CheckBox mapsCheckBox = new CheckBox();
	private CheckBox chartsCheckBox = new CheckBox();

	final PopupPanel imagePopUp = new PopupPanel(true);
	private Image mapPreview = new Image(IMG_MAP_PREVIEW);
	private Image chartPreview = new Image(IMG_CHART_PREVIEW);

	public SelectTabsToAddPopUp() {

		super();
		this.setTitle(constants.selectTabsToAddTitle());
		this.setSize(SELECT_TABS_TO_ADD_WIDTH, SELECT_TABS_TO_ADD_HEIGHT);
		this.setClosable(true);
		this.setPlain(true);
		this.setLayout(new VerticalLayout());
		this.setCloseAction(Window.CLOSE);

		
		//	Set the maps checkbox and its preview
		mapsCheckBox.setText(constants.maps());
		mapsCheckBox.setTabIndex(0);
		mapsCheckBox.addMouseMoveHandler(new MouseMoveHandler(){
			public void onMouseMove(MouseMoveEvent event) {
				imagePopUp.setWidget(mapPreview);
				imagePopUp.center();
			}
		});
		mapsCheckBox.addMouseOutHandler(new MouseOutHandler(){
			public void onMouseOut(MouseOutEvent event) {
				imagePopUp.hide();
			}
		});

		//	Set the charts checkbox and its preview
		chartsCheckBox.setText(constants.charts());
		chartsCheckBox.setTabIndex(1);
		chartsCheckBox.addMouseMoveHandler(new MouseMoveHandler() {
			public void onMouseMove(MouseMoveEvent event) {
				imagePopUp.setWidget(chartPreview);
				imagePopUp.center();
			}
		});
		chartsCheckBox.addMouseOutHandler(new MouseOutHandler(){
			public void onMouseOut(MouseOutEvent event) {
				imagePopUp.hide();
			}
		});


		Button confirmButton = new Button(constants.addTabButton());
		confirmButton.setTabIndex(2);
		confirmButton.addListener(new ButtonListenerAdapter() {
			public void onClick(Button button, EventObject e) {

				if(mapsCheckBox.isChecked()){
					MapUI newMapUI = new MapUI();
					KaitzenGWTSandbox.getCenterPanel().getTabPanel().add(newMapUI);
				}

				if(chartsCheckBox.isChecked()){
					Panel newChartUI = new ChartUI();
					KaitzenGWTSandbox.getCenterPanel().getTabPanel().add(newChartUI);
				}

				close();//	Add the new Tabs and then close the Pop Up
			}
		});


		this.add(mapsCheckBox);
		this.add(chartsCheckBox);
		this.add(confirmButton);
	}


	//  Getters & Setters
	public CheckBox getMapsCheckBox() {
		return mapsCheckBox;
	}

	public void setMapsCheckBox(CheckBox mapsCheckBox) {
		this.mapsCheckBox = mapsCheckBox;
	}

	public CheckBox getChartsCheckBox() {
		return chartsCheckBox;
	}

	public void setChartsCheckBox(CheckBox chartsCheckBox) {
		this.chartsCheckBox = chartsCheckBox;
	}



}//  End Class
